package com.example.shixunandjavagotoyangchen.BoosYang.Day001.Day00105;

import com.example.shixunandjavagotoyangchen.BoosYang.Day001.Day00104.PizzaDay00104Okhttp;

import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * 作者:二徒
 * 时间：2021/10/28- 11:45
 * 功能实现：
 */
public class ClassroomDay00105Okhttp {

    public static ClassroomDay00105Okhttp okhttp;
    public static Retrofit retrofit;
    public static ClassroomDay00105Okhttp getOkhttp(){
        if (okhttp==null){
            synchronized (ClassroomDay00105Okhttp.class){
                if (okhttp==null){
                    okhttp = new ClassroomDay00105Okhttp();
                }
            }
        }
        return okhttp;
    }



    public Retrofit getRetrofit(){
        if (retrofit==null){
            synchronized (Retrofit.class){
                if (retrofit==null){
                    retrofit  = new Retrofit.Builder()
                            .baseUrl("http://82.156.173.100:8087/")
                            .client(new OkHttpClient.Builder()
                                    .addInterceptor(new HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY))
                                    .build())
                            .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
                            .addConverterFactory(GsonConverterFactory.create())
                            .build();
                }
            }
        }
        return retrofit;
    }
}
